﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.Web.Mvc;

namespace ATest.Tests.MockObjects
{
    public class MockHttpRequest : Moq.Mock<HttpRequestBase>
    {
        public MockHttpRequest()
        {
            Setup(x => x.Headers).Returns(Headers);
        }

        public WebHeaderCollection Headers = new WebHeaderCollection();

        public void SetAjax(bool value)
        {
            if (value)
            {
                Headers["X-Requested-With"] = "XMLHttpRequest";
            }
            else
            {
                Headers.Remove("X-Requested-With");
            }
        }

        public void SetRequestType(string requestType)
        {
            Setup(x => x.RequestType).Returns(requestType);
        }

        public FormCollection Form { get; private set; }
        public void EnsureForm()
        {
            if (Form == null)
            {
                Form = new FormCollection();
                Setup(x => x.Form).Returns(Form);
            }
        }

        public void SetFormValue(string key, string name)
        {
            EnsureForm();
            Form[key] = name;
        }
    }
}
